package org.feng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.feng.entity.RoleUser;
import org.feng.mapper.RoleUserMapper;
import org.feng.service.IRoleUserService;
import org.springframework.stereotype.Service;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户角色关系表 服务实现类
 * </p>
 *
 * @author fengjinsong
 * @since 2023-09-02
 */
@Service
public class RoleUserServiceImpl extends ServiceImpl<RoleUserMapper, RoleUser> implements IRoleUserService {

    @Override
    public Set<Integer> getRoleIdSet(Integer userId) {
        LambdaQueryWrapper<RoleUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(RoleUser::getUserId, userId);

        return this.list(queryWrapper).stream()
                .mapToInt(RoleUser::getRoleId)
                .boxed().collect(Collectors.toSet());
    }
}
